/**
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.commons.utils;

import java.util.HashMap;

/**
 * enum <=> int 関係を保持する為のmap
 * 
 * @author aileron
 * @param <T>
 * 
 */
public class InterconversionMap<T>
{
    /**
     * int から enum への変換
     * 
     * @param key
     * @return enum
     */
    public T convert(final int key)
    {
        return iMap.get(key);
    }

    /**
     * enum から int への変換
     * 
     * @param key
     * @return int
     */
    public int convert(final T key)
    {
        return eMap.get(key);
    }

    /**
     * int <=> enum の関係を設定
     * 
     * @param intValue
     * @param enumValue
     * 
     */
    public void set(final int intValue, final T enumValue)
    {
        iMap.put(intValue,
                enumValue);
        eMap.put(enumValue,
                intValue);
    }

    /**
     * int map
     */
    private final HashMap<Integer, T> iMap = new HashMap<Integer, T>();

    /**
     * enum map
     */
    private final HashMap<T, Integer> eMap = new HashMap<T, Integer>();
}